package com.qc.dao.impl;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.qc.dao.BusinessJobDao;
import com.qc.entity.BusinessJob;

@SuppressWarnings({ "unchecked", "rawtypes" })
@Repository("businessJobDao")
public class BusinessJobDaoImpl implements BusinessJobDao{

	@Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;
	
	
	@Override
	public BusinessJob getBusinessJobId(long tId) {
		
		String sql = "select a.t_id,"
				+ "	a.shop_id,a.title,"
				+ "	a.start_date,a.end_date,"
				+ " a.sex,a.skill,"
				+ " a.age,a.age_two,"
				+ " a.num,a.school,"
				+ " a.appearance,a.sec_height,"
				+ " a.sec_height_two,a.content"
				+ " from t_business_job a "
				+ " left join t_merchant b on b.shop_id = a.shop_id "
                + " where 1 = 1 "
                + " and a.shop_id = '"+tId+"'";
		
		BusinessJob informEntity = new BusinessJob();
		
        try {
            informEntity = (BusinessJob)jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper(BusinessJob.class));
        } catch (DataAccessException e) {
        }
        return informEntity;
	}

	@Override
	public int saveBusinessJob(BusinessJob businessJob) {
		
		String sql = "insert into t_business_job(shop_id,title,start_date,end_date,sex,skill,age,age_two,num,school,appearance,sec_height,sec_height_two,content) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		
		return jdbcTemplate.update(sql, new Object[]{
						businessJob.getShopId(),businessJob.getTitle(),
						businessJob.getStartDate(),businessJob.getEndDate(),
						businessJob.getSex(),businessJob.getSkill(),
						businessJob.getAge(),businessJob.getAgeTwo(),
						businessJob.getNum(),businessJob.getSchool(),
						businessJob.getAppearance(),businessJob.getSecHeight(),
						businessJob.getSecHeightTwo(),businessJob.getContent()});
	}

	@Override
	public int deleteBusinessJobId(long id) {
		return 0;
	}

	@Override
	public int updateBusinessJobId(BusinessJob businessJob) {
		
		String sql = "update t_business_job set title = ? , start_date = ? , "
				+ "	end_date = ? , sex = ? , "
				+ "	skill = ? , age = ? , "
				+ "	age_two = ? , num = ? , "
				+ "	school  = ? , appearance  = ? , "
				+ " sec_height  = ? , sec_height_two  = ? , "
				+ " content  = ? "
				+ " where t_id = ?";
		return jdbcTemplate.update(sql, new Object[]{
				businessJob.getTitle(),
				businessJob.getStartDate(),businessJob.getEndDate(),
				businessJob.getSex(),businessJob.getSkill(),
				businessJob.getAge(),businessJob.getAgeTwo(),
				businessJob.getNum(),businessJob.getSchool(),
				businessJob.getAppearance(),businessJob.getSecHeight(),
				businessJob.getSecHeightTwo(),businessJob.getContent(),
				businessJob.gettId()});
	}

}
